﻿namespace Renci.iRods.Studio.Modules.Explorer.Models
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Renci.iRods.Data;
    using System.ComponentModel;
    using Microsoft.Practices.Prism.Commands;
    using Renci.iRods.Studio.Common;

    public class CollectionModel : ExplorerItemModel
    {
        private IRodsCollection _collection;

        public override string TypeName
        {
            get { return "Collection"; }
        }

        public override bool HasChildren
        {
            get { return true; }
        }

        [DisplayName("Parent Name"), ReadOnly(true), Browsable(true)]
        public string ParentName { get; private set; }

        [DisplayName("Map Id"), ReadOnly(true), Browsable(true)]
        public long MapId { get; private set; }

        [DisplayName("Inheritance"), ReadOnly(true), Browsable(true)]
        public string Inheritance { get; private set; }

        [DisplayName("Comments"), ReadOnly(true), Browsable(true)]
        public string Comments { get; private set; }

        [DisplayName("Info 1"), ReadOnly(true), Browsable(true)]
        public string Info1 { get; private set; }

        [DisplayName("Info 2"), ReadOnly(true), Browsable(true)]
        public string Info2 { get; private set; }

        private IEnumerable<MetadataModel> _metadata;
        public override IEnumerable<MetadataModel> Metadata
        {
            get
            {
                if (this._metadata == null)
                {
                    this._metadata = from m in this._collection.MetaData.Take(10)
                                     select new MetadataModel(m.ID, m.Namespace, m.Name, m.Value, m.Unit);
                }

                return this._metadata;
            }
        }

        internal CollectionModel(IRodsConnection connection, IRodsCollection collection)
            : base(connection)
        {
            this._collection = collection;
            this.ID = this._collection.ID;
            this.Name = this._collection.Name;
            this.FullName = this._collection.FullName;
            this.OwnerName = this._collection.OwnerName;
            this.OwnerZone = this._collection.OwnerZone;
            this.CreationTime = this._collection.CreationTime;
            this.LastWriteTime = this._collection.LastWriteTime;
            this.ParentName = this._collection.ParentName;
            this.MapId = this._collection.MapId;
            this.Inheritance = this._collection.Inheritance;
            this.Comments = this._collection.Comments;
            this.Info1 = this._collection.Info1;
            this.Info2 = this._collection.Info2;
        }

        protected override IList<MenuItem> GetContextCommands()
        {
            return null;
        }
    }
}
